﻿using PLCS.Application.Contracts.OrderApp.Dtos;
using PLCS.Domain.Shared.Tasks;

using System.Threading.Tasks;

namespace PLCS.App.OrderTask.ViewModels.Order;

internal class OrderViewModel : NavigationPagedCurdViewModel<OrderDto, OrderEditDto, IOrderService>
{
    private string _orderNo;

    public string OrderNo
    {
        get { return _orderNo; }
        set { SetProperty(ref _orderNo, value); }
    }

    public OrderViewModel(IOrderService service) : base(service)
    {
        View = "工单管理";
    }

    /// <summary>
    /// 获取数据
    /// </summary>
    /// <param name="pageIndex"></param>
    public override async Task GetPageData(int pageIndex)
    {
        try
        {
            UpdateLoading(true);
            var res = await _service.GetListBySearchAsync((pageIndex - 1) * PageSize, PageSize, OrderNo);
            TotalCount = (int)res.TotalCount;
            SetPageCount();
            DataGridList = res.Items.ToObservable();
        }
        finally
        {
            UpdateLoading(false);
        }
    }
}